package us.kg.kotoriforest.senior.dao.impl;

import us.kg.kotoriforest.senior.dao.BankDAO;
import us.kg.kotoriforest.senior.dao.BaseDAO;

import java.sql.SQLException;

/**
 * ClassName: us.kg.kotoriforest.senior.dao.impl.BankDAOImpl </br>
 * Description: File Description
 *
 * @author Kotori rotroutine@163.com
 * @since 2024/11/29
 */
public class BankDAOImpl extends BaseDAO implements BankDAO {
    @Override
    public int addMoney(int id, int money) throws RuntimeException {
        String SQL = "UPDATE t_bank SET money = money + ? WHERE id = ?";
        try {
            return executeUpdate(SQL, money, id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int subMoney(int id, int money) throws RuntimeException {
        String SQL = "UPDATE t_bank SET money = money - ? WHERE id = ?";
        try {
            return executeUpdate(SQL, money, id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
